package com.lineage.server.world;

import com.lineage.server.model.Instance.L1CrockInstance;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class WorldCrock {
  private static final Log _log = LogFactory.getLog(WorldCrock.class);
  
  private static WorldCrock _instance;
  
  private final ConcurrentHashMap<Integer, L1CrockInstance> _crockList;
  
  private Collection<L1CrockInstance> _allCrock;
  
  public static WorldCrock get() {
    if (_instance == null)
      _instance = new WorldCrock(); 
    return _instance;
  }
  
  private WorldCrock() {
    this._crockList = new ConcurrentHashMap<>();
  }
  
  public Collection<L1CrockInstance> all() {
    try {
      Collection<L1CrockInstance> vs = this._allCrock;
      return (vs != null) ? vs : (this._allCrock = Collections.unmodifiableCollection(this._crockList.values()));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
      return null;
    } 
  }
  
  public ConcurrentHashMap<Integer, L1CrockInstance> map() {
    return this._crockList;
  }
  
  public void put(int key, L1CrockInstance value) {
    try {
      this._crockList.put(Integer.valueOf(key), value);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void remove(int key) {
    try {
      this._crockList.remove(Integer.valueOf(key));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
